package com.cxx.food.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cxx.food.dto.*;
import com.cxx.food.service.FoodService;
import com.cxx.food.vo.FoodQueryVo;
import com.fasterxml.jackson.annotation.JsonView;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/food")
@Tag(name = "美食记录")
public class FoodController {
    @Resource
    private FoodService foodService;

    @Operation(summary = "新增美食菜谱")
    @PostMapping("/recipe")
    public Boolean addRecipe(@RequestBody @JsonView(WriteView.class) @Validated RecipeDto recipeDto) {
        return foodService.addRecipe(recipeDto);
    }

    @Operation(summary = "更新美食菜谱")
    @PutMapping("/recipe/{id}")
    public Boolean updateRecipe(@PathVariable("id") long id,
                                @RequestBody @JsonView(WriteView.class) RecipeDto recipeDto) {
        return foodService.updateRecipe(id, recipeDto);
    }

    @Operation(summary = "删除美食菜谱")
    @DeleteMapping("/recipe/{id}")
    public Boolean deleteRecipe(@PathVariable("id") long id) {
        return foodService.deleteRecipe(id);
    }

    @Operation(summary = "查询用户美食菜谱")
    @GetMapping("/recipe/user/{id}")
    public List<SummaryDto> queryRecipeByUser(@PathVariable("id") long id) {
        return foodService.queryRecipeByUser(id);
    }

    @Operation(summary = "查询用户收藏菜谱")
    @GetMapping("/recipe/user/favourite")
    public List<SummaryDto> queryRecipeUserFavourite() {
        return foodService.queryRecipeUserFavourite();
    }

    @Operation(summary = "查询美食菜谱")
    @GetMapping("/recipe")
    public List<SummaryDto> queryRecipeSummary(FoodQueryVo foodQueryVo) {
        return foodService.queryRecipeSummary(foodQueryVo);
    }

    @Operation(summary = "分页查询美食菜谱")
    @GetMapping("/recipe/page")
    public IPage<SummaryDto> querySummaryByPage(@RequestParam("currentPage") Integer currentPage,
                                                @RequestParam("pageSize") Integer pageSize,
                                                FoodQueryVo foodQueryVo) {
        return foodService.querySummaryByPage(currentPage, pageSize, foodQueryVo);
    }

    @Operation(summary = "根据id查询美食")
    @GetMapping("/recipe/{id}")
    public @JsonView(ReadView.class) RecipeDto queryRecipeById(@PathVariable("id") long id) {
        return foodService.queryRecipeById(id);
    }

    @Operation(summary = "查询所有美食名称")
    @GetMapping("/recipe/name")
    public List<String> queryFoodName() {
        return foodService.queryFoodName();
    }

    @Operation(summary = "新增美食成果")
    @PostMapping("/record")
    public Boolean addRecord(@RequestBody @JsonView(WriteView.class) @Validated RecordDto recordDto) {
        return foodService.addRecord(recordDto);
    }

    @Operation(summary = "更新美食成果")
    @PutMapping("/record/{id}")
    public Boolean updateRecord(@PathVariable("id") long id,
                                @RequestBody @JsonView(WriteView.class) RecordDto recordDto) {
        return foodService.updateRecord(id, recordDto);
    }

    @Operation(summary = "删除美食成果")
    @DeleteMapping("/record/{id}")
    public Boolean deleteRecord(@PathVariable("id") long id) {
        return foodService.deleteRecord(id);
    }

    @Operation(summary = "查询美食记录")
    @GetMapping("/record")
    public @JsonView(ReadView.class) List<RecordDto> queryRecord(@RequestParam("startDate") String startDate,
                                                                 @RequestParam("endDate") String endDate) {
        return foodService.queryRecord(startDate, endDate);
    }

    @Operation(summary = "新增评论")
    @PostMapping("/recipe/{id}/comment")
    public Boolean addComment(@PathVariable("id") long id,
                              @RequestParam String content) {
        return foodService.addComment(id, content);
    }

    @Operation(summary = "增加点赞")
    @PostMapping("/recipe/{id}/like")
    public Boolean addLike(@PathVariable("id") long id) {
        return foodService.addLike(id);
    }

    @Operation(summary = "取消点赞")
    @DeleteMapping("/recipe/{id}/like")
    public Boolean deleteLike(@PathVariable("id") long id) {
        return foodService.deleteLike(id);
    }

    @Operation(summary = "增加收藏")
    @PostMapping("/recipe/{id}/favourite")
    public Boolean addFavourite(@PathVariable("id") long id) {
        return foodService.addFavourite(id);
    }

    @Operation(summary = "取消收藏")
    @DeleteMapping("/recipe/{id}/favourite")
    public Boolean deleteFavourite(@PathVariable("id") long id) {
        return foodService.deleteFavourite(id);
    }

    @Operation(summary = "查询美食类别")
    @GetMapping("/category")
    public List<String> queryCategory() {
        return foodService.queryCategory();
    }

    @Operation(summary = "查询美食统计")
    @GetMapping("/stats")
    public StatsDto queryStats() {
        return foodService.queryStats();
    }

    @Operation(summary = "查询美食记录统计")
    @GetMapping("/stats/record")
    public List<StatsChartDto> queryRecordStats() {
        return foodService.queryRecordStats();
    }

    @Operation(summary = "查询美食类别统计")
    @GetMapping("/stats/category")
    public List<StatsChartDto> queryCategoryStats() {
        return foodService.queryCategoryStats();
    }

    @Operation(summary = "查询美食排行榜统计")
    @GetMapping("/stats/rank")
    public List<StatsChartDto> queryRankStats() {
        return foodService.queryRankStats();
    }
}
    